package com.rgs.base.core.util.excel.bo;

import com.rgs.base.core.util.excel.ExcelColumnAnnotation;
import lombok.Data;

import java.lang.reflect.Field;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author Ren Gaoshuai
 * @date 2022-03-08 15:45
 **/
@Data
public class FieldAnnotationBO {
    private Field field;
    private ExcelColumnAnnotation excelColumnAnnotation;
    private List<FieldAnnotationBO> children;

    public FieldAnnotationBO(Field field, ExcelColumnAnnotation excelColumnAnnotation) {
        this.field = field;
        this.excelColumnAnnotation = excelColumnAnnotation;
    }

    public List<FieldExcelColumnBO> getChildrenNameList() {
        if (children == null) {
            return Collections.singletonList(new FieldExcelColumnBO(field, excelColumnAnnotation));
        }
        return children.stream().flatMap(q -> {
            List<FieldExcelColumnBO> childrenNameListTemp = q.getChildrenNameList();
            return childrenNameListTemp.stream()
                    .peek(p -> p.addFirst(this.field, excelColumnAnnotation));
        }).collect(Collectors.toList());
    }
}
